#include "NDialogWindow.h"
#include <string>
#include <iostream>
using namespace std;

NDialogWindow::NDialogWindow() : NWindow(80, LINES, 0, 0, true)
{
    keypad(window, true);
    x = 0;
    y = 0;
}

void NDialogWindow::setPrompt(string newPrompt)
{
    prompt = newPrompt;
}

void NDialogWindow::center()
{
    y = LINES  / 2;
    x = (COLS - prompt.size()) / 2;
}

string NDialogWindow::getInput()
{
    show();
    while (true)
    {
	    string input;
        chtype c = wgetch(window);
        switch(c)
        {
            case 10: // Enter key pressed
                return input;
            default:
                input += c;
                mvwprintw(window, 0, 0, " * %c * ", c);
        }
    }
}

void NDialogWindow::show()
{
    if (! visible)
    {
        visible = true;
        redraw();
    }
}

void NDialogWindow::redraw()
{
    printString(x, y, prompt);
    refresh();
}

NDialogWindow::~NDialogWindow()
{
}
